package com.cheng.example.atguigu.view2.client22;

import cn.hutool.core.collection.ConcurrentHashSet;

import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;


/**
 * 集合类不安全之并发修改异常
 *
 * 源码解析，待学习
 */
public class ContainerNotSafeDemo1 {

    public static void main(String[] args) {
        CopyOnWriteArraySet<String> list = new CopyOnWriteArraySet<>();
        list.add("A");
        list.add("B");
        list.add("C");
        // java.util.ConcurrentModificationException
        for (String s : list) {
            list.add("D");
            System.out.println(s);
        }
        System.out.println(list);
    }
}
